clear
import excel "results.xlsx", sheet("Sheet1") firstrow

*drops the outliers
quietly summarize mcfk
replace mcfk=. if mcfk>r(mean)+2*r(sd)
replace mcfk=. if mcfk<r(mean)-2*r(sd)
replace mcfk_form=. if mcfk==.

*drops the outliers
quietly summarize mcfn
replace mcfn=. if mcfn>r(mean)+2*r(sd)
replace mcfn=. if mcfn<r(mean)-2*r(sd)
replace mcfn_form=. if mcfn==.

*assigns rankings 
sort mcfk
egen rankk = rank(mcfk) if mcfk>0
egen rankkneg= rank(mcfk) if mcfk<0 
quietly summarize rankk
replace rankk= rankkneg + r(max) if rankk==. 
*assigns rankings of negative mcf values
drop rankkneg

*assigns rankings 
sort mcfn
egen rankn = rank(mcfn) if mcfn>0
egen ranknneg= rank(mcfn) if mcfn<0 
quietly summarize rankn
replace rankn= ranknneg + r(max) if rankn==.
*assigns rankings of negative mcf values
drop ranknneg

sort mcfc
egen rankc = rank(mcfc)

sort mcfk_form
egen rankk_form = rank(mcfk_form)

sort mcfc_form
egen rankc_form = rank(mcfc_form)

sort mcfn_form
egen rankn_form = rank(mcfn_form)

gen income=log(Yf)

gen cgdp=C/Yf*100
gen kgdp=K/Yf*100
gen rgdp=R/Yf*100
gen lrate=(Nf+Ni)/(16*330)*100
gen infrate=Yi/Yf

/////mcfk
/*
////PLOTS
twoway (scatter  mcfk infrate , mlabel(country))(lfit mcfk infrate ),ytitle("MCFK") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono) 
graph export "mcfk1.png", as(png) replace

twoway (scatter  mcfk income, mlabel(country))(lfit mcfk income ),ytitle("MCFK") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk3.png", as(png) replace

twoway (scatter  mcfk tauk , mlabel(country))(lfit mcfk tauk ),ytitle("MCFK") xtitle("Capital Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk5.png", as(png) replace

twoway (scatter  mcfk kgdp , mlabel(country))(lfit mcfk kgdp ),ytitle("MCFK") xtitle("Capital Level(%GDP)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk7.png", as(png) replace

twoway (scatter  rankk infrate , mlabel(country))(lfit rankk infrate ),ytitle("Ranking of MCFK") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono) 
graph export "mcfk2.png", as(png) replace

twoway (scatter  rankk income, mlabel(country))(lfit rankk income ),ytitle("Ranking of MCFK") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk4.png", as(png) replace

twoway (scatter  rankk tauk , mlabel(country))(lfit rankk tauk ),ytitle("Ranking of MCFK") xtitle("Capital Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk6.png", as(png) replace

twoway (scatter  rankk kgdp , mlabel(country))(lfit rankk kgdp ),ytitle("Ranking of MCFK") xtitle("Capital Level(%GDP)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk8.png", as(png) replace


////MCFN

///PLOTS
twoway (scatter  mcfn infrate  , mlabel(country))(lfit mcfn infrate ),ytitle("MCFN") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn1.png", as(png) replace

twoway (scatter  mcfn income , mlabel(country))(lfit mcfn income ),ytitle("MCFN") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn3.png", as(png) replace

twoway (scatter  mcfn taun , mlabel(country))(lfit mcfn taun ),ytitle("MCFN") xtitle("Labor Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn5.png", as(png) replace

twoway (scatter  mcfn lrate , mlabel(country))(lfit mcfn lrate ),ytitle("MCFN") xtitle("Labor Hours(%Total Hours)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn7.png", as(png) replace

twoway (scatter  rankn infrate  , mlabel(country))(lfit rankn infrate ),ytitle("Ranking of MCFN") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn2.png", as(png) replace

twoway (scatter  rankn income , mlabel(country))(lfit rankn income ),ytitle("Ranking of MCFN") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn4.png", as(png) replace

twoway (scatter  rankn taun , mlabel(country))(lfit rankn taun ),ytitle("Ranking of MCFN") xtitle("Labor Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn6.png", as(png) replace

twoway (scatter  rankn lrate , mlabel(country))(lfit rankn lrate ),ytitle("Ranking of MCFN") xtitle("Labor Hours(%Total Hours)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn8.png", as(png) replace

////MCFC

///PLOTS
twoway (scatter  mcfc infrate , mlabel(country))(lfit mcfc infrate ),ytitle("MCFC") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc1.png", as(png) replace

twoway (scatter  mcfc income , mlabel(country))(lfit mcfc income ),ytitle("MCFC") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc3.png", as(png) replace

twoway (scatter  mcfc tauc , mlabel(country))(lfit mcfc tauc ),ytitle("MCFC") xtitle("Consumption Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc5.png", as(png) replace

twoway (scatter  mcfc cgdp , mlabel(country))(lfit mcfc cgdp ),ytitle("MCFC") xtitle("Consumption Level(%GDP)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc7.png", as(png) replace

twoway (scatter  rankc infrate , mlabel(country))(lfit rankc infrate ),ytitle("Ranking of MCFC") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc2.png", as(png) replace

twoway (scatter  rankc income , mlabel(country))(lfit rankc income ),ytitle("Ranking of MCFC") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc4.png", as(png) replace

twoway (scatter  rankc tauc , mlabel(country))(lfit rankc tauc ),ytitle("Ranking of MCFC") xtitle("Consumption Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc6.png", as(png) replace

twoway (scatter  rankc cgdp , mlabel(country))(lfit rankc cgdp ),ytitle("Ranking of MCFC") xtitle("Consumption Level(%GDP)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc8.png", as(png) replace
}
*/
gen cgdp_form=C_form/Yf*100
gen kgdp_form=K_form/Yf*100
gen lrate_form=(labor_form)/(16*330)*100

/////mcfk_form
/*
////PLOTS
twoway (scatter  mcfk_form infrate , mlabel(country))(lfit mcfk_form infrate ),ytitle("MCFK") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono) 
graph export "mcfk_form1.png", as(png) replace

twoway (scatter  mcfk_form income , mlabel(country))(lfit mcfk_form income ),ytitle("MCFK") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk_form3.png", as(png) replace

twoway (scatter  mcfk_form tauk , mlabel(country))(lfit mcfk_form tauk ),ytitle("MCFK") xtitle("Capital Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk_form5.png", as(png) replace

twoway (scatter  mcfk_form kgdp_form , mlabel(country))(lfit mcfk_form kgdp ),ytitle("MCFK") xtitle("Capital Level(%GDP)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk_form7.png", as(png) replace

twoway (scatter  rankk_form infrate , mlabel(country))(lfit rankk_form infrate ),ytitle("MCFK") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono) 
graph export "mcfk_form2.png", as(png) replace

twoway (scatter  rankk_form income , mlabel(country))(lfit rankk_form income ),ytitle("MCFK") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk_form4.png", as(png) replace

twoway (scatter  rankk_form tauk , mlabel(country))(lfit rankk_form tauk ),ytitle("MCFK") xtitle("Capital Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk_form6.png", as(png) replace

twoway (scatter  rankk_form kgdp_form , mlabel(country))(lfit rankk_form kgdp ),ytitle("MCFK") xtitle("Capital Level(%GDP)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfk_form8.png", as(png) replace

////MCFN

///PLOTS
twoway (scatter  mcfn_form infrate , mlabel(country))(lfit mcfn_form infrate ),ytitle("MCFN") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn_form1.png", as(png) replace

twoway (scatter  mcfn_form income , mlabel(country))(lfit mcfn_form income ),ytitle("MCFN") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn_form3.png", as(png) replace

twoway (scatter  mcfn_form taun , mlabel(country))(lfit mcfn_form taun ),ytitle("MCFN") xtitle("Labor Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn_form5.png", as(png) replace

twoway (scatter  mcfn_form lrate_form , mlabel(country))(lfit mcfn_form lrate_form),ytitle("MCFN") xtitle("Labor Hours(%Total Hours)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn_form7.png", as(png) replace

twoway (scatter  rankn_form infrate , mlabel(country))(lfit rankn_form infrate ),ytitle("MCFN") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn_form2.png", as(png) replace

twoway (scatter  rankn_form income , mlabel(country))(lfit rankn_form income ),ytitle("MCFN") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn_form4.png", as(png) replace

twoway (scatter  rankn_form taun , mlabel(country))(lfit rankn_form taun ),ytitle("MCFN") xtitle("Labor Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn_form6.png", as(png) replace

twoway (scatter  rankn_form lrate_form , mlabel(country))(lfit rankn_form lrate_form),ytitle("MCFN") xtitle("Labor Hours(%Total Hours)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfn_form8.png", as(png) replace


////MCFC

///PLOTS
twoway (scatter  mcfc_form infrate , mlabel(country))(lfit mcfc_form infrate ),ytitle("MCFC") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc_form1.png", as(png) replace

twoway (scatter  mcfc_form income , mlabel(country))(lfit mcfc_form income ),ytitle("MCFC") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc_form3.png", as(png) replace

twoway (scatter  mcfc_form tauc , mlabel(country))(lfit mcfc_form tauc ),ytitle("MCFC") xtitle("Consumption Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc_form5.png", as(png) replace

twoway (scatter  mcfc_form cgdp_form , mlabel(country))(lfit mcfc_form cgdp_form ),ytitle("MCFC") xtitle("Consumption Level(%GDP)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc_form7.png", as(png) replace

twoway (scatter  rankc_form infrate , mlabel(country))(lfit rankc_form infrate ),ytitle("Ranking of MCFC") xtitle("Informality Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc_form2.png", as(png) replace

twoway (scatter  rankc_form income , mlabel(country))(lfit rankc_form income ),ytitle("Ranking of MCFC") xtitle("Per capita GDP") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc_form4.png", as(png) replace

twoway (scatter  rankc_form tauc , mlabel(country))(lfit rankc_form tauc ),ytitle("Ranking of MCFC") xtitle("Consumption Tax Rate") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc_form6.png", as(png) replace

twoway (scatter  rankc_form cgdp_form , mlabel(country))(lfit rankc_form cgdp_form ),ytitle("Ranking of MCFC") xtitle("Consumption Level(%GDP)") legend(off) graphregion(color(white)) scheme(s1mono)
graph export "mcfc_form8.png", as(png) replace
*/

twoway (rspike mcfk mcfk_form tauk) (scatter mcfk tauk, msymbol(D)) (scatter mcfk_form tauk, msymbol(S)),ytitle("MCPF of Capital Tax") xtitle("Capital Tax Rate") legend(order(2 3) lab(2 "With Informality") lab(3 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "tauk_both.png", as(png) replace
twoway (rspike mcfn mcfn_form taun) (scatter mcfn taun, msymbol(D)) (scatter mcfn_form taun, msymbol(S)),ytitle("MCPF of Labor Tax") xtitle("Labor Tax Rate") legend(order(2 3) lab(2 "With Informality") lab(3 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "taun_both.png", as(png) replace
twoway (rspike mcfc mcfc_form tauc) (scatter mcfc tauc, msymbol(D)) (scatter mcfc_form tauc, msymbol(S)),ytitle("MCPF of Consumption Tax") xtitle("Consumption Tax Rate") legend(order(2 3) lab(2 "With Informality") lab(3 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "tauc_both.png", as(png) replace

twoway (rspike mcfk mcfk_form infrate) (scatter mcfk infrate, msymbol(D)) (scatter mcfk_form infrate, msymbol(S)),ytitle("MCPF of Capital Tax") xtitle("Informality") legend(order(2 3) lab(2 "With Informality") lab(3 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "inf_mck_both.png", as(png) replace
twoway (rspike mcfn mcfn_form infrate) (scatter mcfn infrate, msymbol(D)) (scatter mcfn_form infrate, msymbol(S)),ytitle("MCPF of Labor Tax") xtitle("Informality") legend(order(2 3) lab(2 "With Informality") lab(3 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "inf_mcn_both.png", as(png) replace
twoway (rspike mcfc mcfc_form infrate) (scatter mcfc infrate, msymbol(D)) (scatter mcfc_form infrate, msymbol(S)),ytitle("MCPF of Consumption Tax") xtitle("Informality") legend(order(2 3) lab(2 "With Informality") lab(3 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "inf_mcc_both.png", as(png) replace

twoway (rspike rankk rankk_form infrate) (scatter rankk infrate, msymbol(D)) (lfit rankk infrate) (scatter rankk_form infrate, msymbol(S))(lfit rankk_form infrate),ytitle("MCPF of Capital Tax") xtitle("Informality") legend(order(2 4) lab(2 "With Informality") lab(4 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "inf_mck_both_rank.png", as(png) replace
twoway (rspike rankn rankn_form infrate) (scatter rankn infrate, msymbol(D)) (lfit rankn infrate)(scatter rankn_form infrate, msymbol(S))(lfit rankn_form infrate),ytitle("MCPF of Labor Tax") xtitle("Informality") legend(order(2 4) lab(2 "With Informality") lab(4 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "inf_mcn_both_rank.png", as(png) replace
twoway (rspike rankc rankc_form infrate) (scatter rankc infrate, msymbol(D)) (lfit rankc infrate)(scatter rankc_form infrate, msymbol(S))(lfit rankc_form infrate),ytitle("MCPF of Consumption Tax") xtitle("Informality") legend(order(2 4) lab(2 "With Informality") lab(4 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "inf_mcc_both_rank.png", as(png) replace

twoway (rspike rankk rankk_form tauk) (scatter rankk tauk, msymbol(D))(lfit rankk tauk) (scatter rankk_form tauk, msymbol(S))(lfit rankk_form tauk),ytitle("MCPF of Capital Tax") xtitle("Capital Tax Rate") legend(order(2 4) lab(2 "With Informality") lab(4 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "tauk_both_rank.png", as(png) replace
twoway (rspike rankn rankn_form taun) (scatter rankn taun, msymbol(D)) (lfit rankn taun)(scatter rankn_form taun, msymbol(S))(lfit rankn_form taun),ytitle("MCPF of Labor Tax") xtitle("Labor Tax Rate") legend(order(2 4) lab(2 "With Informality") lab(4 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "taun_both_rank.png", as(png) replace
twoway (rspike rankc rankc_form tauc) (scatter rankc tauc, msymbol(D))(lfit rankc tauc) (scatter rankc_form tauc, msymbol(S))(lfit rankc_form tauc),ytitle("MCPF of Consumption Tax") xtitle("Consumption Tax Rate") legend(order(2 4) lab(2 "With Informality") lab(4 "Without Informality") ) graphregion(color(white)) scheme(s1mono)
graph export "tauc_both_rank.png", as(png) replace


/*
////TABLES

///CORR
estpost corr rankk tauk income infrate kgdp , matrix
esttab . using mcfkcorr.tex, not unstack compress noobs replace booktabs page


/////CORR
estpost corr rankn taun income infrate lrate, matrix
esttab . using mcfncorr.tex, not unstack compress noobs replace booktabs page


/////CORR
estpost corr rankc tauc income infrate cgdp , matrix
esttab . using mcfccorr.tex, not unstack compress noobs replace booktabs page

///CORR
estpost corr rankk_form tauk income infrate kgdp_form , matrix
esttab . using mcfk_formcorr.tex, not unstack compress noobs replace booktabs page


/////CORR
estpost corr rankn_form taun income infrate  lrate_form, matrix
esttab . using mcfn_formcorr.tex, not unstack compress noobs replace booktabs page

/////CORR
estpost corr rankc_form tauc income infrate cgdp_form , matrix
esttab . using mcfc_formcorr.tex, not unstack compress noobs replace booktabs page
